#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/4/20 12:36
# @Author  : LiShan
# @Email   : lishan_1997@126.com
# @File    : evaluate.py
# @Note    : this is note
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# names = ["step", "time", "sim", "flow", "queue", "delay"]
# result = pd.read_csv("./resource/tmp/record/2021-04-20-12-30-53.txt", sep="\s+", header=2, error_bad_lines=False, names=names)
# print(result["step"])

delay = []
with open("../resource/tmp/record/2021-04-20-12-30-53.txt", "r") as f:
    lines = f.readlines()
for i in range(4+5, len(lines)):
    line = lines[i].split()[-1][1:-1]
    delay.append(float(line))

print(delay)

legend_lable = ["DQN"]

# 绘图
x = np.linspace(0, len(delay), len(delay))
plt.plot(x, delay)

# 设置坐标轴范围
# plt.xlim([0, 200])
# plt.ylim([0.3, 1.0])

# 设置坐标轴刻度
# plt.xticks(range(0, 225, 25))
# plt.yticks(np.arange(0.3, 1.1, 0.1))

# 设置坐标轴名称
plt.xlabel("Step", fontproperties='Times New Roman', size=10.5)
plt.ylabel("delay", fontproperties='Times New Roman', size=10.5)

# 设置网格
plt.grid()

# 设置图例
plt.legend(legend_lable, loc="lower right", frameon=False)

# 设置标题
plt.title("Average delay variation", fontproperties='SimSun', size=10.5)

# 保存图片
plt.savefig("2021-04-20-12-30-53.svg")
plt.show()
